package com.bRoom.common;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;


@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class  ServerResponse<T> {

    private  int status;

    private  String msg;

    private  T data;


    @JsonIgnore
    public  boolean isSuccess()
    {
        return this.status==ResponseCode.SUCCESS.getCode();
    }


    public  static <T> ServerResponse <T>  createBySuccess(){
        return new ServerResponse <T> (ResponseCode.SUCCESS.getCode());
    }

    public  static <T> ServerResponse <T>  createBySuccessData(T data){
        return new ServerResponse <T> (ResponseCode.SUCCESS.getCode(),data);
    }

    public static  <T> ServerResponse <T> createBySuccessMsg(String msg){
         return  new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),msg);
    }
    public  static  <T> ServerResponse <T> createBySuccessMsgData(String msg ,T data){
         return  new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),msg,data);
    }


    public  static  <T> ServerResponse <T> createByError(){
         return  new ServerResponse<T>(ResponseCode.ERROR.getCode());
    }
    public  static  <T> ServerResponse <T> createByErrorMsg(String msg){
         return  new ServerResponse<T>(ResponseCode.ERROR.getCode(),msg);
    }

    public ServerResponse(int status) {
        this.status = status;
    }

    public ServerResponse(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ServerResponse(int status, T data) {
        this.status = status;
        this.data = data;
    }

    public ServerResponse(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public ServerResponse(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
